using System.Globalization;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Babylon.Toolbox
{
    public struct VertexPositionNormalTexture : IVertexType
    {
        static readonly VertexDeclaration vertexDeclaration = new VertexDeclaration(
                    new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
                    new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
                    new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
                    );

        public Vector3 Position;
        public Vector3 Normal;
        public Vector2 TextureCoordinates;

        public VertexDeclaration VertexDeclaration
        {
            get { return vertexDeclaration; }
        }

        public Vector3 GetPosition()
        {
            return Position;
        }

        public string Key
        {
            get { return ToString(); }
        }

        public override string ToString()
        {
            return string.Format(CultureInfo.CurrentCulture, "{{P:{0} N:{1} TV:{2}}}", Position, Normal, TextureCoordinates);
        }

        public static bool operator ==(VertexPositionNormalTexture left, VertexPositionNormalTexture right)
        {
            return ((left.Position == right.Position) && (left.Normal == right.Normal) && (left.TextureCoordinates == right.TextureCoordinates));
        }

        public static bool operator !=(VertexPositionNormalTexture left, VertexPositionNormalTexture right)
        {
            return !(left == right);
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }
            if (obj.GetType() != GetType())
            {
                return false;
            }
            return (this == ((VertexPositionNormalTexture)obj));
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}

